﻿using System;
using System.Web.Mvc;
using Downloader.Domain;
using Downloader.Domain.Contracts.Tasks;
using Downloader.Web.Controllers.Queries;
using Downloader.Web.Controllers.ViewModels;
using SharpArch.NHibernate.Web.Mvc;

namespace Downloader.Web.Controllers.Admin
{
    public class CommentController : Controller
    {
        public ICommentTasks CommentTasks { get; set; }
        public ICommentQuery CommentQuery { get; set; }
        //
        // GET: /Comment/
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult List(int index, int size)
        {
            var result = CommentQuery.GetList(index, size);
            return PartialView(result);
        }

        [Transaction]
        public ActionResult SaveOrUpdate(Comment category)
        {
            try
            {
                CommentTasks.CreateOrUpdate(category);
            }
            catch (Exception exc)
            {
                return Json(new { success = false, data = exc.Message });
            }
            return Json(new { success = true });
        }

        public ActionResult Edit(int id)
        {
            var model = CommentTasks.Get(id);
            var viewModel = new CommentViewModel(model);
            return Json(new { data = viewModel }, JsonRequestBehavior.AllowGet);
        }
        [Transaction]
        public ActionResult Dele(int id)
        {
            try
            {
                CommentTasks.Delete(id);
                return Json(new { success = true });
            }
            catch (Exception e)
            {
                return Json(new { success = false, data = e.Message });
            }
        }

    }
}
